package com.gurun.camera.addDevice;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.danale.sdk.platform.constant.device.OnlineType;
import com.danale.sdk.platform.constant.deviceinfo.AddedState;
import com.gurun.camera.R;
import com.gurun.camera.addDevice.entity.DeviceInfoEntity;
import com.gurun.camera.addDevice.view.ISearchDevView;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/12/23.
 */

public class SearchCameraDeviceAdapter extends RecyclerView.Adapter<SearchCameraDeviceAdapter.SearchViewHolder> {

    private Context mContext;
    private List<DeviceInfoEntity> mDatas = new ArrayList<>();
    private ISearchDevView mISearchDevView;

    public SearchCameraDeviceAdapter(Context context, List<DeviceInfoEntity> list, ISearchDevView iSearchDevView) {
        mContext = context;
        mDatas.addAll(list);
        mISearchDevView = iSearchDevView;
    }

    public void updateDataSrc(List<DeviceInfoEntity> list) {
        mDatas.clear();
        mDatas.addAll(list);
        notifyDataSetChanged();
    }

    @Override
    public SearchViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_search_camera_device, parent, false);
        SearchViewHolder holder = new SearchViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(SearchViewHolder holder, int position) {
        final DeviceInfoEntity deviceInfoEntity = mDatas.get(position);
//        holder.mOwnerTv.setText(deviceInfoEntity.getOwnerAccount());
//        holder.mIdTv.setText(deviceInfoEntity.getDeviceId());
//        holder.mOnlineType.setText(deviceInfoEntity.getModel());
//        holder.mAddStatus.setText(deviceInfoEntity.getCompany());
//
//        if (deviceInfoEntity.getOnlineType() == OnlineType.ONLINE && deviceInfoEntity.getAddedState() == AddedState.NOT_ADDED) {
//            holder.mAddButton.setVisibility(View.VISIBLE);
//            holder.mOwnerTv.setVisibility(View.GONE);
//            holder.mOwnerTitle.setVisibility(View.GONE);
//            holder.mAddButton.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//                    if (mISearchDevView != null) {
//                        mISearchDevView.onAddDevice(deviceInfoEntity.getDeviceId());
//                    }
//                }
//            });
//        } else {
//            holder.mAddButton.setVisibility(View.GONE);
//            holder.mOwnerTv.setVisibility(View.VISIBLE);
//            holder.mOwnerTitle.setVisibility(View.VISIBLE);
//        }
    }

    @Override
    public int getItemCount() {
        return mDatas.size();
    }

    class SearchViewHolder extends RecyclerView.ViewHolder {

        TextView mOwnerTv;
        TextView mIdTv;
        TextView mOnlineType;
        TextView mAddStatus;
        ImageView mAddButton;

        TextView mOwnerTitle;

        public SearchViewHolder(View itemView) {
            super(itemView);
//            mIdTv = (TextView) itemView.findViewById(R.id.tv_id_content);
//            mOwnerTv = (TextView) itemView.findViewById(R.id.tv_owner_content);
//            mOnlineType = (TextView) itemView.findViewById(R.id.tv_onlinet_content);
//            mAddStatus = (TextView) itemView.findViewById(R.id.tv_addstatus_content);
//            mAddButton = (ImageView) itemView.findViewById(R.id.iv_add);
//            mOwnerTitle = (TextView) itemView.findViewById(R.id.tv_owner_title);
        }
    }
}
